<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
				xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:param name="user" />

  <xsl:param name="pageState" /><!-- "READONLY" / "MODIFY" / "CREATE" -->

  <xsl:template match="/tasks">
	<html>
	  <head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta content="user-scalable=no,width=device-width" name="viewport" />
		<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />
		<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
		<script src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>
		<title>Liste des tâches</title>
	  </head>
	  <body>
		<div data-role="header">
		  <xsl:choose>
			<xsl:when test="$user">
			  <h1>Toutes les tâches de <xsl:value-of select="$user"/></h1>
			</xsl:when>
			<xsl:otherwise>
			  <h1>Toutes les tâches</h1>
			</xsl:otherwise>
		  </xsl:choose>
			<a title="Retour" href="#" data-icon="back" data-iconpos="notext" data-rel="back">Retour</a>


		</div>
		<div data-role="content">
		  <!--
      		  tri par deadline (plus récent en 1er) puis par priorité (de la
			  plus petite la plus grande)
      	  -->
		  <table>
			<tr>
			  <th>Finie</th>
			  <th>Id</th>
			  <th>Titre</th>
			  <th>Description</th>
			  <th>Deadline</th>
			  <th>Priorité</th>
			  <th>Responsable</th>
			  <th>Demandeur</th>
			  <th>Date de création</th>
			  <th>Voir</th> <th>Modifier</th>
			</tr>
			<xsl:for-each select="task">
			  <xsl:sort select="substring(@deadline,7,4)" data-type="number" />
			  <xsl:sort select="substring(@deadline,4,2)" data-type="number" />
			  <xsl:sort select="substring(@deadline,1,2)" data-type="number" />

			  <xsl:if test="$user='' or $user=owner/text()">

				<tr>
				  <xsl:if test="@done='true'">
					<xsl:attribute name="style">text-decoration: line-through;</xsl:attribute>
				  </xsl:if>


				  <td><xsl:value-of select="@done"/></td>
				  <td><xsl:value-of select="@id"/></td>
				  <td><xsl:value-of select="@title"/></td>
				  <td><xsl:value-of select="description"/></td>
				  <td><xsl:value-of select="@deadline"/></td>
				  <td><xsl:value-of select="@priority"/></td>
				  <td><xsl:value-of select="owner"/></td>
				  <td><xsl:value-of select="asker"/></td>
				  <td><xsl:value-of select="@creationDate"/></td>
				  <td>
					<a target="_self" data-role="button" data-iconpos="notext" data-icon="search">
					  <xsl:attribute name="href">view?id=<xsl:value-of select="@id"/></xsl:attribute>
					  Voir
					</a>
				  </td>
				  <td>
					<a target="_self" data-role="button" data-iconpos="notext" data-icon="gear">
					  <xsl:attribute name="href">modify?id=<xsl:value-of select="@id"/></xsl:attribute>
					  Modifier
					</a>
				  </td>
				</tr>
			  </xsl:if>
			</xsl:for-each>
		  </table>
		</div>
	  </body>
	</html>
  </xsl:template>
</xsl:stylesheet>
